﻿using IRepositoryBll;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using RepositoryCommon;
using RepositoryEntity;
using RepositorySystem.Models;
using RepositorySystem.Models.UserInfoViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RepositorySystem.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    public class UserInfoController : Controller
    {
        //private IUserInfoBll _userInfoBll;
        //private IDepartmentInfoBll _departmentInfoBll;
        //public UserInfoController(IUserInfoBll userInfoBll, IDepartmentInfoBll departmentInfoBll)
        //{
        //    _userInfoBll = userInfoBll;
        //    _departmentInfoBll = departmentInfoBll;
        //}

        //public IActionResult UserInfoListView(AddUserInfoViewModel model)
        //{
        //    return View();
        //}

        ///// <summary>
        ///// 添加用户用页面
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public IActionResult AddUserInfoView(AddUserInfoViewModel model)
        //{
        //    return View();
        //}

        ///// <summary>
        ///// 添加用户
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public IActionResult AddUserInfo(AddUserInfoViewModel model)
        //{
        //    CustomActionResult res = new CustomActionResult();

        //    if (string.IsNullOrEmpty(model.Account))
        //    {
        //        res.Msg = "账号不能为空";
        //        return Json(res);
        //    }
        //    else if (string.IsNullOrEmpty(model.PassWord))
        //    {
        //        res.Msg = "密码不能为空";
        //        return Json(res);
        //    }
        //    else if (string.IsNullOrEmpty(model.UserName))
        //    {
        //        res.Msg = "用户名不能为空";
        //        return Json(res);
        //    }

        //    UserInfo entity = new UserInfo()
        //    {
        //        ID = Guid.NewGuid().ToString(),
        //        Account = model.Account,
        //        UserName = model.UserName,
        //        PhoneNum = model.PhoneNum,
        //        Email = model.Email,
        //        Sex = model.Sex,
        //        IsAdmin = model.IsAdmin,
        //        //添加用户数据时，对密码进行MD5加密
        //        PassWord = MD5Help.md5(model.PassWord),
        //        CreateTime = DateTime.Now,
        //        IsDelete = false,
        //        DepartmentID = model.DepartmentId
        //    };

        //    bool isSuccess = _userInfoBll.Add(entity);
        //    if (isSuccess)
        //    {
        //        res.IsSuccess = true;
        //        res.Msg = "添加成功";
        //        return Json(res);
        //    }
        //    else
        //    {
        //        return Json(res);
        //    }
        //}

        ///// <summary>
        ///// 修改用户用页面
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public IActionResult UpdateUserInfoView()
        //{
            

        //    return View();
        //}

        ///// <summary>
        ///// 获取更新用户页面信息
        ///// </summary>
        ///// <param name="userInfoId"></param>
        ///// <returns></returns>
        //public IActionResult GetUpdateUserInfo(string userInfoId)
        //{
        //    CustomActionResult res = new CustomActionResult();
        //    //获取用户信息
        //    UserInfo userInfo = _userInfoBll.GetEntity(userInfoId);
        //    //查询部门信息下拉选数据
        //    object departmentInfos = _departmentInfoBll.GetDepartmentSelectOption();
        //    res.IsSuccess = true;
        //    res.Status = 1;
        //    res.Msg = "成功";
        //    res.Data = new
        //    {
        //        UserInfo = userInfo,
        //        DepartmentInfos = departmentInfos
        //    };
        //    return Json(res);
        //}


        ///// <summary>
        ///// 更新用户
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public IActionResult UpdateUserInfo(UpdateUserInfoViewModel model)
        //{
        //    CustomActionResult res = new CustomActionResult();
        //    if (_userInfoBll.UpdateUserInfo(model.ID, model.UserName, model.Sex, model.PhoneNum ,model.DepartmentId))
        //    {
        //        res.IsSuccess = true;
        //        res.Msg = "添加成功";
        //        return Json(res);
        //    }
        //    else
        //    {
        //        return Json(res);
        //    }
        //}

        ///// <summary>
        ///// 删除用户
        ///// </summary>
        ///// <param name="userInfoId"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public IActionResult DeleteUserInfo(string userInfoId)
        //{
        //    if (_userInfoBll.SoftDeleteEntity(userInfoId))
        //    {
        //        return Json("OK");
        //    }
        //    else
        //    {
        //        return Json("Error");
        //    }
        //}

        ///// <summary>
        ///// 根据id获取用户信息
        ///// </summary>
        ///// <param name="userInfoId"></param>
        ///// <returns></returns>
        //public IActionResult GetUserInfo(string userInfoId)
        //{
        //    UserInfo userInfo = _userInfoBll.GetEntity(userInfoId);
        //    if (userInfo == null)
        //    {
        //        return Json("Error");
        //    }
        //    else
        //    {
        //        return Json(userInfo);
        //    }
        //}

        ///// <summary>
        ///// /获取用户集合
        ///// </summary>
        ///// <returns></returns>
        //public IActionResult GetUserInfoList(int page, int limit, string userName, string phoneNum)
        //{
        //    int count;

        //    object userInfos = _userInfoBll.GetUserInfoListByPage(page, limit, out count, userName, phoneNum);

        //    return Json(new
        //    {
        //        code = 0,
        //        msg = "成功",
        //        count = count,
        //        data = userInfos
        //    });
        //}

        ///// <summary>
        ///// 获取部门下拉集合
        ///// </summary>
        ///// <returns></returns>
        //public IActionResult GetDepartmentSelectOption()
        //{
        //    CustomActionResult res = new CustomActionResult();
        //    //查询部门集合
        //     object options = _departmentInfoBll.GetDepartmentSelectOption();
        //    res.IsSuccess = true;
        //    res.Msg = "成功";
        //    res.Status = 1;
        //    res.Data = options;
        //    return Json(res);
        //}
    }
}
